<template>
    <div class="project-form">
        <div v-if="form">
            <h4 class="form-name-text" style="text-align: center;"> {{ form.title }} </h4>
            <span class="form-name-text" style="text-align: center">{{ form.describes }}</span>
            <el-divider>
            </el-divider>
            <project-form
                @submit="submitForm"
                :projectConfig="projectConfig"
                v-if="projectConfig.projectKey"/>
        </div>
    </div>
</template>

<script>
import {postKeyValueRequest,postRequest,getRequest} from '@/api/api'
import ProjectForm from './ProjectForm'
export default {
    data(){
        return{
            form: null,
            formItem:{},
            projectConfig: {
                projectKey: '',
                preview: false,
                showBtns: true
            },
        }
    },
    created() {
    this.projectConfig.projectKey = this.$route.query.key
    },
    mounted(){
        // 获取表单标题和描述
        getRequest(`/project/getByKey?key=${this.$route.query.key}`).then(res => {
            this.form = res.data
        })
        // 获取表单item
        //getRequest(`/project/item/list?key=${this.$route.query.key}`).then(resp=>{
            // this.formItem = resp.data
            //console.log(resp.data)
        //})
    },
    components: {
        ProjectForm
    },
    methods:{
        submitForm(data) {
            postRequest(`/project/result/create`,{
                'projectKey': this.$route.query.key,
                'originalData': data.formModel,
                'processData': data.labelFormModel
            }).then(res=>{
                this.$router.push({path: '/success'})
            })
        }
    }
}
</script>

<style>

</style>